<template>
	<div class="role" v-if="dialogFormVisible">
		<el-dialog :title="title" :visible="dialogFormVisible" width="800px" :close-on-click-modal="false" :before-close="handleClose">
			<div class="tab">
				<el-form ref="form" :rules="rules" :model="form" label-width="80px">
					<el-form-item label="样机名称" >
						<el-input v-model="form.name" placeholder="请输入样机名称" :disabled="true"></el-input>
					</el-form-item>
					<el-form-item label="样机型号" >
						<el-input v-model="form.model" placeholder="请输入样机型号" :disabled="true"></el-input>
					</el-form-item>
					<el-form-item label="硬件版本" >
						<el-input v-model="form.hardware_version" placeholder="请输入硬件版本" :disabled="true"></el-input>
					</el-form-item>
					<el-form-item label="接收人">
						<el-select
							v-model="form.receive_user"
							placeholder="请选择"
							style="width:100%;">
							<el-option
								v-for="item in options"
								:key="item.id"
								:label="item.name"
								:value="item.id">
							</el-option>
						</el-select>
					</el-form-item>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="handleClose">取 消</el-button>
				<el-button type="primary" @click="add('form')" v-if="num != 3">提 交</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import { getHeader } from '@/app.config'
import {userList,transfer} from '@/api/user'

export default {
	name: 'addForm',
	data(){
		return {
			headers:{'Content-Type':'multipart/form-data'},
			dialogFormVisible:false,
			form:{
				name:''
			},
			id:'',
			rules:{

			},
			options:[],
			num:0,
			title:'借出',
			fileList:[]
		}
	},
	created() {

	},
	methods:{
		handleClose(){
			this.dialogFormVisible = false
			this.form = {}
		},
		add(form){
			this.$refs[form].validate((valid) => {
				if (valid) {
					var source = `${process.env.VUE_APP_KANBAN_HOST}/api/v1/prototype/${this.id}/transfer`;
					var data = {
						'receive_user':this.form.receive_user
					}
					this.$axios.post(source,data,{headers: getHeader()})
						.then((response) => {
							if (response.status == 200) {
								this.dialogFormVisible = false
								this.form = {}
								this.$parent.initTable()
								this.$message.success(response.data.message)
							}
						}).catch((err) => {
						console.log(err);
					});
				} else {
					return false;
				}
			});

		},
		initData(num,data){
			this.num = num
			this.id = data._id
			this.form = Object.assign({},data)
			userList().then(res => {
				this.options = res.data
			})
		}
	}

}
</script>

<style lang="scss" scoped>
.role{
	//.tab{
	//	width: 450px;
	//	margin: 0 0 0 40px;
	//}
}
</style>
